﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Comm100.Framework;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class ChatbotLearningQuestionsController : ControllerBase
    {

        private readonly IChatbotLearningQuestionAppService _app;
        public ChatbotLearningQuestionsController(IChatbotLearningQuestionAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("learningQuestions/{id:Guid}")]
        public ActionResult<ChatbotLearningQuestionDto> Get([FromRoute] Guid id, [FromQuery] string include)
        {
            ChatbotLearningQuestionDto learningQuestion = _app.Get(id, include);
            return Ok(learningQuestion);
        }

        [HttpGet]
        [Route("bots/{botId:Guid}/learningQuestions")]
        public ActionResult<PagedListDto<ChatbotLearningQuestionDto>> GetList([FromRoute] Guid botId
            ,[FromQuery]LearningQuestionQueryDto dto, [FromQuery]Paging paging, [FromQuery] string include)
        {
            PagedListDto<ChatbotLearningQuestionDto> list = _app.GetList(botId, dto, paging, include);
            return Ok(list);
        }

        [HttpPost]
        [Route("bots/{botId:Guid}/learningQuestions:batchCreate")]
        public ActionResult Post([FromRoute] Guid botId, [FromBody] List<string> questions)
        {
            var opId = _app.BatchAddQuestions(botId, questions);
            return Ok(new { operationId = opId });
        }

        [HttpDelete]
        [Route("learningQuestions/{id:Guid}")]
        public ActionResult Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }
        [HttpDelete]
        [Route("learningQuestions")]
        public ActionResult BatchDelete([FromBody] List<Guid> ids)
        {
            foreach (var id in ids)
            {
                _app.Delete(id);
            }
            return NoContent();
        }
    }
}
